package com.sc.nft.dao;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.ApplicationRequirement;
import com.sc.nft.entity.vo.ApplicationRequirementSelectListVO;
import com.sc.nft.enums.ApplicationRequirementEnum;
import com.sc.nft.mapper.ApplicationRequirementMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * (ApplicationRequirement)表Dao层
 *
 * @author wwc
 * @since 2023-07-18 16:27:29
 */
@Slf4j
@Repository
public class ApplicationRequirementDao extends ServiceImpl<ApplicationRequirementMapper, ApplicationRequirement> {

    public Boolean selectBean(ApplicationRequirement applicationRequirement) {
        return baseMapper.selectBean(applicationRequirement) > 0;
    }

    public List<ApplicationRequirementSelectListVO> selectList(Integer serveType) {
        LambdaQueryWrapper<ApplicationRequirement> applicationRequirementLambdaQueryWrapper = Wrappers.lambdaQuery();
        applicationRequirementLambdaQueryWrapper.eq(ApplicationRequirement::getServeType, serveType);
        return BeanUtil.copyToList(baseMapper.selectList(applicationRequirementLambdaQueryWrapper), ApplicationRequirementSelectListVO.class);
    }

    public List<ApplicationRequirement> selectListByType(Integer type) {
        LambdaQueryWrapper<ApplicationRequirement> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(ApplicationRequirement::getServeType, type);
        return baseMapper.selectList(wrapper);
    }

    public List<ApplicationRequirement> selectListByServeTypeAndType(Integer serveType, ApplicationRequirementEnum ... type) {
        LambdaQueryWrapper<ApplicationRequirement> wrapper = Wrappers.lambdaQuery();
        wrapper.in(ApplicationRequirement::getType, type);
        wrapper.groupBy(ApplicationRequirement::getType);
        return baseMapper.selectList(wrapper);
    }
}
